package com.zeji.androidadvance.activity.videolist;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.zeji.androidadvance.R;

public class VideoItemFragment extends Fragment {
    View contentView;
    TextView tvUrl;
    View viewOther;

    String url;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        contentView = inflater.inflate(R.layout.item_video_list_layout, container, false);
        initView();
        return contentView;
    }

    private void initView() {
        tvUrl = contentView.findViewById(R.id.itemVideoUrl);
        tvUrl.setText(url);
        viewOther = contentView.findViewById(R.id.itemVideoOther);
    }

    void setUrl(String url) {
        this.url = url;
        if (tvUrl != null) {
            tvUrl.setText(url);
        }
    }

    void setOffsetRatio(float offsetRatio) {
        if (viewOther == null) {
            return;
        }
        float calc = 1 - offsetRatio * 2;
        float alpha = Math.min(1, Math.max(0, calc));
        viewOther.setAlpha(alpha);
    }
}
